﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnitofworkManager.Business;

namespace UnitOfWorkUnit
{
    class Program
    {
        static void Main(string[] args)
        {

        }
        static bool AddOrder(Order order)
        {
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                order.CheckOrder();
                order.Products.ForEach(item => { item.CheckProducts(); });
                OrderGateway orderGateway = new OrderGateway(unitOfWork);
                var orderDbResult = orderGateway.AddOrder(order);
                OrderProductsGateway productGateway = new OrderProductsGateway(unitOfWork);
                var productDbResult = productGateway.AddOrderProducts(order.Products);
                if (orderDbResult && productDbResult)
                {
                    if (unitOfWork.Commit())
                    {
                        //this.SendOrderIntegrationMssage(order);//发送成功集成订单消息   
                        return true;  
                    }
                    //this.PushOrderProcessQueue(order);//将本次订单发送到处理队列中  
                    return false;  
                }
                //this.LogBusinessException(order);//记录一个业务处理异常LOG，以备排查问题。  
                return false;  
            }

            return false;
        }
    }
}
